package com.ron.android.daneel;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import com.ron.provider.Daneel;

public class FilterEntry extends Activity {

	@Override
	protected void onCreate(Bundle icicle) {
		super.onCreate(icicle);
		setContentView(R.layout.filter_entry);
		
		EditText containsText = (EditText) findViewById( R.id.contains_entry_text );
		EditText notContainsText = (EditText) findViewById( R.id.notcontains_entry_text );
		
		containsText.setText(getIntent().getExtras().getString(Daneel.TEXT_CONTAINS_KEY));
		notContainsText.setText(getIntent().getExtras().getString(Daneel.TEXT_NOT_CONTAINS_KEY));
		
		final Button okButton = (Button) findViewById(R.id.filter_entry_ok_button);
		okButton.setOnClickListener(new Button.OnClickListener() {
			@Override
			public void onClick(View v) {
				String contains = null;
				String notContains = null;
				
				EditText containsText = (EditText) findViewById( R.id.contains_entry_text );
				EditText notContainsText = (EditText) findViewById( R.id.notcontains_entry_text );
				
				if( containsText.getText().toString().length() > 0 ){
					contains = containsText.getText().toString();
				}
				if( notContainsText.getText().toString().length() > 0 ){
					notContains = notContainsText.getText().toString();
				}
				
				Bundle filters = new Bundle();
				filters.putString( Daneel.TEXT_CONTAINS_KEY, contains );
				filters.putString( Daneel.TEXT_NOT_CONTAINS_KEY, notContains );
				
				setResult( Daneel.SUBACTIVITY_SUCEEDED, null, filters );
				finish();
			}
		});

		final Button cancelButton = (Button) findViewById(R.id.filter_entry_cancel_button);
		cancelButton.setOnClickListener(new Button.OnClickListener() {
			@Override
			public void onClick(View v) {
				setResult( Daneel.SUBACTIVITY_CANCELLED );
				finish();
			}
		});
		
	}

}
